package es.unex.meigas.dataObjects;

/**
 * A convenience class which implements some of the methods
 * of the ITable interface. Extending this class is recommended
 * instead of implementing the interface directly
 * @author volaya
 *
 */
public abstract class AbstractTable implements ITable {

	protected Object m_BaseDataObject;

	public Object getBaseDataObject(){

		return m_BaseDataObject;

	}

	public String[] getFieldNames() {

		String[] names = new String[getFieldCount()];

		for (int i = 0; i < names.length; i++) {
			names[i] = getFieldName(i);
		}

		return names;

	}


	public Class[] getFieldTypes() {

		Class[] types = new Class[getFieldCount()];

		for (int i = 0; i < types.length; i++) {
			types[i] = getFieldType(i);
		}

		return types;

	}

	public int getFieldIndexByName(String sFieldName){

		for (int i = 0; i < this.getFieldCount(); i++) {
			String sName = getFieldName(i);
			if (sName.equals(sFieldName)){
				return i;
			}
		}

		return -1;

	}

	public String toString(){

		return this.getName();

	}


}
